home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / ipc / mainpipefork.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  556b  |  34 lines

  1. main()
  2. {
  3.     int    childpid, pipe1[2], pipe2[2];
  4.  
  5.     if (pipe(pipe1) < 0 || pipe(pipe2) < 0)
  6.         err_sys("can't create pipes");
  7.  
  8.     if ( (childpid = fork()) < 0) {
  9.         err_sys("can't fork");
  10.  
  11.     } else if (childpid > 0) {            /* parent */
  12.         close(pipe1[0]);
  13.         close(pipe2[1]);
  14.  
  15.         client(pipe2[0], pipe1[1]);
  16.  
  17.         while (wait((int *) 0) != childpid)    /* wait for child */
  18.             ;
  19.  
  20.         close(pipe1[1]);
  21.         close(pipe2[0]);
  22.         exit(0);
  23.     } else {                    /* child */
  24.         close(pipe1[1]);
  25.         close(pipe2[0]);
  26.  
  27.         server(pipe1[0], pipe2[1]);
  28.  
  29.         close(pipe1[0]);
  30.         close(pipe2[1]);
  31.         exit(0);
  32.     }
  33. }
  34.